package com.liwei.vip.mall.goods.controller;

import com.liwei.mall.util.RespResult;
import com.liwei.vip.mall.goods.model.Category;
import com.liwei.vip.mall.goods.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 根据分类父ID查询所有子类 parent_id
     *
     * @param pid
     */
    @GetMapping("/parent/{id}")
    public RespResult<List<Category>> findByParentId(@PathVariable("id") Integer pid){
        return RespResult.ok(categoryService.findByParentId(pid));
    }
}
